package com.ff.exerpro.common;

import com.ff.exerpro.exception.BussExceptionEnum;
import lombok.Data;

// R也要用@Data,这个注意不要再犯
@Data
public class R<T> {
    private Integer code;

    private String msg;

    private T data;

    public static <T> R<T> success(T data) {
        R<T> r = new R<T>();
        r.code = BussExceptionEnum.SUCCESS.getCode();
        r.msg = BussExceptionEnum.SUCCESS.getMsg();
        r.data = data;
        return r;
    }

    public static <T> R<T> success() {
        return success(null);
    }

    public static <T> R<T> error() {
        return error(null);
    }

    public static <T> R<T> error(T data) {
        R<T> r = new R<T>();
        r.code = BussExceptionEnum.ERROR.getCode();
        r.msg = BussExceptionEnum.ERROR.getMsg();
        r.data = data;
        return r;
    }

    public static <T> R<T> error(Integer code, String msg) {
        R<T> r = new R<T>();
        r.code = code;
        r.msg = msg;
        return r;
    }

    public static <T> R<T> error(Integer code, String msg, T data) {
        R<T> r = new R<T>();
        r.code = code;
        r.msg = msg;
        r.data = data;
        return r;
    }
}
